package com.ok.community.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ok.common.exception.CustomException;
import com.ok.community.domain.po.OkCard;
import com.ok.community.domain.po.OkCommentCategory;
import com.ok.community.mapper.OkCommentCategoryMapper;
import com.ok.community.service.IOkCardService;
import com.ok.community.service.IOkCommentCategoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 帖子分类表 服务实现类
 * </p>
 *
 * @author author
 * @since 2024-04-29
 */
@Service
@RequiredArgsConstructor
public class OkCommentCategoryServiceImpl extends ServiceImpl<OkCommentCategoryMapper, OkCommentCategory> implements IOkCommentCategoryService {

    private final IOkCardService okCardService;

    @Override
    public void removeWith(Long id) {
        LambdaQueryWrapper<OkCard> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(OkCard::getCategoryId,id);
        int count = okCardService.count();
        if (count != 0){
            throw new CustomException("该分类关联帖子，不能删除");
        }

        this.removeById(id);
    }
}
